#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar('\n');
}

const int MAXN = 1e5+10;

int n,m,a[MAXN],cov[MAXN<<2],inv[MAXN<<2];

struct node{
	int siz,val,l1,r1,l0,r0,tot;
	node (int l=0,int r=0,int x=0):siz(r-l+1),val(x),l1(x),r1(x),l0(x),r0(x),tot(x){}
	friend node operator + (node a,node b){
		node c;
		c.val = a.val + b.val;
		c.siz = a.siz + b.siz;
		c.l1 = a.l1 == a.siz? a.l1 + b.l1 : a.l1;
		c.r1 = b.r1 == b.siz? a.r1 + b.r1 : b.r1;
		c.tot = max(a.tot,max(b.tot,a.r1+b.l1));
		return c;
	}
}t[MAXN<<2];

void build(int o = 1,int l = 1,int r = n){
	cov[o] = -1,inv[o] = 0;
	if(l == r) return (void)(t[o](l,r,a[l]));
	int mid = l+r>>1;
	build(o<<1,l,mid),build(o<<1|1,mid+1,r);
	t[o] = t[o<<1] + t[o<<1|1];
}

void pushdown(int o){
	if(cov[o] != -1){
		t[o<<1].val = t[o<<1|1].val = cov[o];
		cov[o<<1] = cov[o<<1|1] = cov[o];
		inv[o<<1] = inv[o<<1|1] = 0;
		cov[o] = -1;
	}else if(inv[o]){
		t[o<<1].val = t[o<<1].siz - t[o<<1].val;
		t[o<<1|1].val = t[o<<1|1].siz - t[o<<1|1].val;
	}
}

void cover(int xl,int xr,int v,int o = 1,int l = 1,int r = n){
	if(l == xl && r == xr){
		t[o].val = cov[o] = v;
		inv[o] = 0;
		return;
	}
	pushdown(o);
}
int main (){
	n = in,m = in;
	for(int i = 1;i <= n;i++) a[i] = in;
	build();
	while(m--){
		int op = in,l = in,r = in;
		switch(op){
		0:
			cover(l,r,0);
			break;
		1:
			cover(l,r,1);
			break;
		2:
			turn(l,r);
		3:
			printf("%d\n",q(l,r));
		4:
			printf("%d\n",q1(l,r));
		}
	}
	return 0;
}
